home *** CD-ROM | disk | FTP | other *** search
- /*
- * Explorer - Version 1.0
- *
- * A Desk Accessory for the Macintosh
- *
- * Copyright (C) 1984 by Manx Software Systems, Inc.
- * May be used, but not sold without permission.
- *
- * written by Jim Goodnow II, December 7-8, 1984
- */
-
- #asm
- _main
- dc.w $2400 ;ctl-enable, need time
- dc.w 5*60 ;update every 5 seconds
- dc.w $000a ;detect mouse and key down events
- dc.w -777 ;menu ID number (must be negative)
-
- dc.w _open-_main ;open routine
- dc.w _nop-_main ;prime routine
- dc.w _control-_main ;control routine
- dc.w _nop-_main ;status routine
- dc.w _close-_main ;close routine
-
- _title
- ; dc.b 8 ;needed for -lc3, remove for -lc2
- dc.b "Explorer"
- dc.b 0 ;needed for -lc2, doesn't hurt for -lc3
- ds 0 ;for alignment
-
- public __Uend,__Dorg,__Cend
-
- _save
- lea _main,a4 ;set up globals -- ech 1/88
- move.l a4,d0 ;remember the _main
- add.l #(__Cend-_main+$8000),a4
- move.l a0,_Pbp ;save pb pointer
- move.l a1,_Dp ;save DCtlEntry pointer
- lea __Uend,a0
- move.w (a0),d1 ; get reloc count
- beq .savedone ; nothing to reloc
- sub.l 2(a0),d0 ; minus old value of _main gives reloc delta
- beq .savedone ; haven't moved since last reloc
- ; first time thru loop updates the saved _main
- .savelp
- add.w #2,a0
- add.l d0,(a0)+
- dbra d1,.savelp
- .savedone
- rts
-
- _restore
- move.l _Pbp,a0
- rts
- #endasm
-
- #define _DRIVER
- #define SMALL_MEM
- #include <Quickdraw.h>
- #include <ToolUtils.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <Controls.h>
- #undef SMALL_MEM
- #include <OSUtils.h>
- #include <Events.h>
- #include <TextEdit.h>
- #include <Files.h>
- #include <Devices.h>
- #include <Desk.h>
-
- #define NLINES 16 /* number of lines in window */
- #define MENUID -777 /* must be negative */
- #define MEMTOP (*(long *)0x108) /* top of memory 128 or 512K */
- #define SP (*(struct storage **)Dp->dCtlStorage)
-
- DCtlPtr Dp;
- CntrlParam *Pbp;
-
- Rect Wind_rect = {100, 150, 275, 360};
- Rect Scrl_rect = {-1, 194, 176, 211};
- Rect Cont_rect = {0, 0, 176, 194};
- Rect Full_rect = {0, 0, 176, 211};
- Rect Edit_rect = {-1, 44, 12, 90};
-
- Cursor Ibeam = {
- 0x3838, 0x3C78, 0x0280, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
- 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0280, 0x3C78, 0x3838,
- 0x3838, 0x3C78, 0x0280, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
- 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0280, 0x3C78, 0x3838,
- 0x0008, 0x0008 };
-
- struct storage {
- MenuHandle menu;
- ControlHandle vscrl;
- char * where;
- short autoupdate;
- short size;
- short incr;
- TEHandle hte;
- };
-
- open()
- {
- register WindowPtr wp;
- register DCtlPtr dp;
- register struct storage *sp;
- Rect r;
- GrafPtr savport;
- extern char title[];
- struct windowpeek {
- GrafPort port;
- int windowKind;
- };
-
- save();
- dp = Dp;
- if (dp->dCtlWindow == 0) {
- HLock(dp->dCtlStorage = NewHandle((long)sizeof(struct storage)));
- sp = SP;
- dp->dCtlWindow =
- wp = NewWindow(0L, &Wind_rect, title, TRUE, noGrowDocProc, -1L, TRUE, 0L);
- ((struct windowpeek *)wp)->windowKind = dp->dCtlRefNum;
- sp->vscrl = NewControl(wp, &Scrl_rect, "", FALSE, 0, 0, 0x7fff, scrollBarProc, 0L);
- wp->txFont = 4; /* Monaco 9 */
- wp->txSize = 9;
- wp->txMode = srcCopy;
- GetPort(&savport);
- SetPort(wp);
- r = Edit_rect;
- InsetRect(&r, 4, 1);
- sp->hte = TENew(&r, &r);
- SetPort(savport);
- sp->size = 8;
- sp->where = -1;
- sp->autoupdate = 0;
- sp->incr = MEMTOP / 0x8000L;
- sp->menu = NewMenu(MENUID, "Explorer");
- AppendMenu(sp->menu,
- "Auto-Refresh;Hand-Refresh;(-;Hexadecimal!\x12;Ascii");
- HUnlock(dp->dCtlStorage);
- }
- restore();
- return(0);
- }
-
- close()
- {
- register DCtlPtr dp;
-
- save();
- dp = Dp;
- TEDispose(SP->hte);
- DisposeWindow(dp->dCtlWindow);
- dp->dCtlWindow = 0;
- DeleteMenu(MENUID);
- DrawMenuBar();
- DisposHandle(SP->menu);
- DisposHandle(dp->dCtlStorage);
- restore();
- return(0);
- }
-
- nop()
- {
- return(0);
- }
-
- control()
- {
- register struct storage *sp;
- Point pt;
- register int item;
-
- save();
- HLock(Dp->dCtlStorage);
- sp = SP;
- SetPort(Dp->dCtlWindow);
- switch(Pbp->csCode) {
- case accEvent:
- doevent(sp, *(EventRecord **)Pbp->csParam);
- break;
- case accRun:
- if (sp->autoupdate)
- draw_wind();
- break;
- case accCursor:
- TEIdle(sp->hte);
- GetMouse(&pt);
- if (PtInRect(&pt, &Edit_rect))
- SetCursor(&Ibeam);
- else
- InitCursor();
- break;
- case accMenu:
- switch(item = ((int *)Pbp->csParam)[1]) {
- case 1: /* auto refresh */
- sp->autoupdate ^= TRUE;
- CheckItem(sp->menu, 1, sp->autoupdate);
- break;
- case 2: /* manual refresh */
- draw_wind();
- break;
- case 4:
- case 5:
- sp->size = item==4?8:16;
- CheckItem(sp->menu, 4, item==4?TRUE:FALSE);
- CheckItem(sp->menu, 5, item==5?TRUE:FALSE);
- EraseRect(&Cont_rect);
- draw_wind();
- break;
- }
- break;
- case accUndo:
- break;
- case accCut:
- TECut(sp->hte);
- break;
- case accCopy:
- TECopy(sp->hte);
- break;
- case accPaste:
- TEPaste(sp->hte);
- break;
- case accClear:
- TEDelete(sp->hte);
- break;
- }
- HUnlock(Dp->dCtlStorage);
- restore();
- return(0);
- }
-
- doevent(sp, ep)
- register struct storage *sp;
- register EventRecord *ep;
- {
- register int c;
- register long l;
- ControlHandle chdl;
- pascal void scrlup(), scrldn();
- long xtol();
-
- switch(ep->what) {
- case keyDown:
- if ((ep->modifiers & (cmdKey | optionKey)) == 0) {
- c = (char)ep->message;
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 8) {
- TEKey(c, sp->hte);
- break;
- }
- if ((c == '\r' || c == 3) && (l = xtol(sp->hte)) != -1) {
- sp->where = (char *)l;
- TESetSelect(0L, 1000L, sp->hte);
- draw_wind();
- break;
- }
- }
- SysBeep(2);
- break;
- case mouseDown:
- GlobalToLocal(&ep->where);
- if (PtInRect(&ep->where, &Cont_rect)) {
- if (PtInRect(&ep->where, &Edit_rect))
- TEClick(&ep->where, ep->modifiers&shiftKey?TRUE:FALSE, sp->hte);
- }
- else {
- c = FindControl(&ep->where, Dp->dCtlWindow, &chdl);
- switch(c) {
- case inUpButton:
- TrackControl(chdl, &ep->where, scrlup);
- break;
- case inDownButton:
- TrackControl(chdl, &ep->where, scrldn);
- break;
- case inPageUp:
- scrlpage(chdl, c, -NLINES);
- break;
- case inPageDown:
- scrlpage(chdl, c, NLINES);
- break;
- case inThumb:
- TrackControl(chdl, &ep->where, 0L);
- sp->where = (char *)((long)sp->incr * GetCtlValue(chdl));
- draw_wind();
- break;
- }
- }
- break;
- case activateEvt:
- if (ep->modifiers&1) {
- if (sp->where == -1) {
- signature();
- sp->where = 0;
- }
- InsertMenu(sp->menu, 0);
- ShowControl(sp->vscrl);
- TEActivate(sp->hte);
- }
- else {
- DeleteMenu(MENUID);
- HideControl(sp->vscrl);
- TEDeactivate(sp->hte);
- }
- DrawMenuBar();
- break;
- case updateEvt:
- BeginUpdate(ep->message);
- draw_wind();
- DrawControls(ep->message);
- EndUpdate(ep->message);
- break;
- }
- }
-
- signature()
- {
- register WindowPtr wp;
- register long tick;
-
- wp = Dp->dCtlWindow;
- wp->txFont = 0;
- wp->txSize = 0;
- MoveTo(70, 20);
- DrawString("version 2");
- MoveTo(90, 40);
- DrawString("by");
- MoveTo(50,60);
- DrawString("Jim Goodnow II");
- MoveTo(55, 80);
- DrawString("using Aztec C");
- MoveTo(10, 110);
- DrawString("Manx ");
- Move(0, 20);
- DrawString("Software ");
- Move(0, 20);
- DrawString("Systems");
- Move(0, 20);
- DrawString("Inc.");
- for (tick=TickCount()+100;TickCount() < tick;)
- ;
- EraseRect(&wp->portRect);
- wp->txFont = 4;
- wp->txSize = 9;
- }
-
- draw_wind()
- {
- register unsigned char *cp, *wp;
- register unsigned long l;
- register int k, i, j;
- struct storage *sp;
- char buf[40];
- static char hex[] = "0123456789abcdef";
-
- sp = SP;
- l = (unsigned long)sp->where;
- if (l < 0)
- l = 0;
- if (l > MEMTOP - sp->size*NLINES)
- l = MEMTOP - sp->size * NLINES;
- wp = (unsigned char *) sp->where = (unsigned char *) l;
- SetCtlValue(sp->vscrl, (int)(l/sp->incr));
- RectRgn(Dp->dCtlWindow->clipRgn, &Cont_rect);
- MoveTo(4, 9);
- DrawString("Start: ");
- TEUpdate(&Edit_rect, sp->hte);
- FrameRect(&Edit_rect);
- for (i=0;i<NLINES;i++) {
- k = i * sp->size;
- MoveTo(4, i*10+24);
- cp = (unsigned char *) buf;
- l =(unsigned long) (wp + k);
- for (j=5;j>=0;l>>=4)
- cp[j--] = hex[l%16];
- cp += 6;
- *cp++ = ':';
- if (sp->size == 8) {
- for (j=0;j<8;j++) {
- *cp++ = ' ';
- *cp++ = hex[wp[k+j]/16];
- *cp++ = hex[wp[k+j]%16];
- }
- }
- *cp = 0;
- DrawString(buf);
- if (sp->size == 16) {
- cp = (unsigned char *)buf;
- *cp++ = ' ';
- for (j=0;j<16;j++) {
- if (wp[k+j] > 0x1f && wp[k+j] < 0x80)
- *cp++ = wp[k+j];
- else
- *cp++ = '.';
- }
- *cp = 0;
- DrawString(buf);
- }
- }
- RectRgn(Dp->dCtlWindow->clipRgn, &Full_rect);
- }
-
- pascal void
- scrlup(chdl, code)
- ControlHandle chdl;
- int code;
- {
- scroll(chdl, code, inUpButton);
- }
-
- pascal void
- scrldn(chdl, code)
- ControlHandle chdl;
- int code;
- {
- scroll(chdl, code, inDownButton);
- }
-
- scroll(chdl, code, where)
- ControlHandle chdl;
- {
- register struct storage *sp;
-
- #asm
- move.l a4,-(sp)
- lea _main,a4 ;set up globals -- ech 1/88
- add.l #(__Cend-_main+$8000),a4
- #endasm
- if (code == where) {
- sp = SP;
- if (where == inUpButton)
- sp->where -= sp->size;
- else
- sp->where += sp->size;
- draw_wind();
- }
- ;
- #asm
- move.l (sp)+,a4
- #endasm
- }
-
- scrlpage(chdl, code, amount)
- ControlHandle chdl;
- {
- Point pt;
- struct storage *sp;
-
- sp = SP;
- do {
- GetMouse(&pt);
- if (TestControl(chdl, &pt) == code) {
- sp->where += sp->size*amount;
- draw_wind();
- }
- } while (StillDown());
- }
-
- long
- xtol(hte)
- TEHandle hte;
- {
- register char *cp;
- register long i = 0, l = 0;
- register int c, n;
-
- n = (*hte)->teLength;
- cp = *(*hte)->hText;
- while (n--) {
- c = *cp++;
- if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- else if (c >= '0' && c <= '9')
- c -= '0';
- else {
- TESetSelect(i, i+1, hte);
- return(-1);
- }
- l = l * 16 + c;
- i++;
- }
- return(l);
- }
-
-